<template>
  <div class="search-box">
    <i class="icon-search"></i>
    <input v-model="query" :placeholder="this.placeholder" class="box" />
    <i v-show="query" @click="deleteQuery" class="icon-dismiss"></i>
  </div>
</template>

<script type="text/ecmascript-6">
  export default {
    data () {
      return {
        query: ''
      }
    },
    props: {
      placeholder: {
        placeholder: String,
        default: '搜索歌手/歌词'
      }
    },
    methods: {
      deleteQuery () {
        this.query = ''
      },
      setQuery (query) {
        this.query = query
      }
    },
    created () {
      this.$watch('query', (newQuery) => {
        this.$emit('query', newQuery)
      })
    }
  }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  @import "../../common/stylus/variable.styl";

  .search-box
    display: flex
    align-items: center
    box-sizing: border-box
    width: 100%
    padding: 0 6px
    height: 40px
    background: $color-highlight-background
    border-radius: 6px
    .icon-search
      font-size: 24px
      color: $color-background
    .box
      flex: 1
      margin: 0 5px
      line-height: 18px
      background: $color-highlight-background
      color: $color-text
      font-size: $font-size-medium
      &::placeholder
        color: $color-text-d
    .icon-dismiss
      font-size: 16px
      color: $color-background
</style>